package com.cwl.dao.impl;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.cwl.dao.UserDao;
import com.cwl.domain.User;


public class UserDaoImpl extends HibernateDaoSupport implements UserDao{

	public void add(User user) {
		this.getHibernateTemplate().save(user);
	}
	public List<User> select(User user) {
		String hql = "from User where name=? and password=?" ;
		Object[] value={user.getName(),user.getPassword()};
		List<User> userlist = this.getHibernateTemplate().find(hql, value);
		return userlist;
	}
	public User selectByName(String name) {
		// TODO Auto-generated method stub
		String hql = "from User where name=?";
		List<User> userlist=this.getHibernateTemplate().find(hql,name);
		if(userlist.size()==0){
			return null;
		}else{
			return userlist.get(0);
		}
	}
	public void updata(User user) {
		this.getHibernateTemplate().update(user);
		
	}
	public User selectById(Integer id) {
		String hql = "from User where id=?";
		List<User> userlist=this.getHibernateTemplate().find(hql,id);
		if(userlist.size()==0){
			return null;
		}else{
			return userlist.get(0);
		}
	}



}
